package com.magicsoft.share.presenter.exchange;

import com.magicsoft.share.base.BasePresenter;
import com.magicsoft.share.bean.exchange.GoodsList;
import com.magicsoft.share.constant.APIService;
import com.magicsoft.share.rx_retrofit_network.location.retrofit.RetrofitUtil;
import com.magicsoft.share.rx_retrofit_network.location.rxandroid.NetWorkTransformer;
import com.magicsoft.share.rx_retrofit_network.location.rxandroid.SimpleObserver;
import com.magicsoft.share.view.exchange.IGoodsFragmentView;

import io.reactivex.annotations.NonNull;

/**
 * Created by lyf on 2017/11/30/030.
 */

public class GoodsFragmentPresenter extends BasePresenter<IGoodsFragmentView> {
    public void goodsList(int goodsType, int pageNum, int pageSize, Integer isRecommend) {
        RetrofitUtil.getApi(APIService.class)
                .goodsList( pageNum,pageSize,goodsType,isRecommend)
                .compose(new NetWorkTransformer<GoodsList>())
//                .compose(new LoadingTransformer<GoodsList>(mContext))
                .subscribe(new SimpleObserver<GoodsList>(mCompositeDisposable) {
                    @Override
                    public void call(@NonNull GoodsList goodsList) {
                        getView().goodsListSuccess(goodsList);
                    }

                    @Override
                    public void showErrorMsg(Throwable e, String errorMsg) {
                        super.showErrorMsg(e, errorMsg);
                        getView().goodsListFail();
                    }
                });
    }
}
